<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<!DOCTYPE html>
<html>
  
  <head>
    <meta charset="UTF-8">
    <title>客户价值列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/font.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/xadmin.js"></script>
      <script charset="utf-8" language="javascript" type="text/javascript" src="JS/CommonFields/common.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  
  <body>
    <div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">客户管理</a>
        <a>
          <cite>客户价值管理</cite></a>
      </span>
      <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
    </div>
<%--根据条件搜索--%>
    <div class="x-body">
        <div class="layui-row">
            <form class="layui-form layui-col-md12 x-so" onsubmit="return false;">
                客户姓名：<input type="text" name="keyWords"  placeholder="客户姓名" autocomplete="off" class="layui-input">
                <div class="layui-inline">
                    <label class="layui-form-label">客户类型</label>
                    <div class="layui-input-inline">
                        <select name="typeId" lay-verify="required">
                        </select>
                    </div>
                </div>
                <button class="layui-btn" id="search"><i class="layui-icon">&#xe615;</i></button>
            </form>
        </div>

      <hr class="layui-border-black">
      <xblock class="do-table">
        客户信息价值列表
      </xblock>
<%--      <table id="data" lay-filter="empl"></table>--%>
        <table id="data" lay-filter="customervalue"></table>


    </div>


    </div>
    <script>
      var table;
      layui.use(['table'], function(){
        table = layui.table;


        table.render({
          elem: '#data'
          ,height: 600
          ,url: '${pageContext.request.contextPath}/customer/valuelist/data' //数据接口
          ,method: "post"
          ,page: true //开启分页
          ,cols: [[ //表头
            {type:'checkbox', fixed: 'left'}
            ,{field: 'customerId', title: 'ID', width:'10%', sort: true}
            ,{field: 'customerName', title: '姓名', width:'10%'}
            ,{field: 'customerGender', title: '性别', width:'10%', templet:function (d) {
                  return d.emplGender === 1 ? '男' : '女';
              }}
            ,{field: 'typeName', title: '客户类型', width: '20%', templet:function (d) {
                return d.type.typeName;
              }}

                ,{field: 'totalConsumption', title: '消费总额（单位：万元）', width: '20%', templet:function (d) {
                    console.log(d.value);
                        return d.value.totalConsumption;
                    }}
                ,{field: 'consumptionTimes', title: '已消费次数', width: '10%', templet:function (d) {
                        return d.value.consumptionTimes;
                    }}
                ,{field: 'serviceRepresentative', title: '服务代表', width: '10%', templet:function (d) {
                        return d.value.serviceRepresentative;
                    }}
                ,{fixed: 'right',title: '操作', width:'20%', align:'center', toolbar: '#do'}
          ]]
        });



        //查看
          table.on('tool(customervalue)', function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
              var data = obj.data; //获得当前行数据
              var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
              var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）

              if(layEvent === 'edit'){ //编辑
                  x_admin_show('编辑员工','${pageContext.request.contextPath}/customer/order/list?id='+data.customerId)
              }
          });


          $('.do-table .layui-btn').on('click', function(){
          var type = $(this).data('type');
          active[type] ? active[type].call(this) : '';
        });

          $("#search").click(function () {
              //获取对应的数据
              // 获取关键字
              var keyWords = $("input[name='keyWords']").val();
              // 获取客户类型
              var typeId =$("select[name='typeId']").val();
              // 组装总共的提交参数
              var param = {keyWords: keyWords, typeId: typeId};
              console.log(keyWords,typeId);


              // 表格数据的重载
              table.reload("data",{where: param})
          });

      });
      var from;
      layui.use(['form','layer'], function(){
          $ = layui.jquery;
          form = layui.form;
          var layer = layui.layer;
// 获取 客户类别列表
          $.ajax({
              type:"post",
              url:"${pageContext.request.contextPath}/customer/typelist/data",
              dataType: "json",
              success:function (res) {
                  console.log(res)
                  if (res.code === 0){
                      $("select[name=typeId]").empty();
                      $(res.data).each(function () {
                          // 动态创建
                          var option = $('<option value="'+this.typeId+'">'+this.typeName+'</option>')
                          // 追加
                          $("select[name=typeId]").append(option);
                      });
                      // 重新渲染表单
                      form.render('select');
                  }
              }
          });

      });
    </script>

    <script type="text/html" id="do">
        <a class="layui-btn layui-btn-xs" lay-event="edit">查看</a>
    </script>

  </body>

</html>